home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PORTABLE.ZIP / UNCTRL.C < prev    next >
Text File  |  1992-11-21  |  2KB  |  76 lines

  1. #define        CURSES_LIBRARY  1
  2. #include <curses.h>
  3. #undef unctrl
  4.  
  5. #ifndef        NDEBUG
  6. char *rcsid_unctrl = "$Header: c:/curses/portable/RCS/unctrl.c%v 2.0 1992/11/15 03:29:19 MH Rel $";
  7. #endif
  8.  
  9.  
  10.  
  11.  
  12. static char strbuf[3] = {0, 0, 0};
  13.  
  14. /*man-start*********************************************************************
  15.  
  16.   unctrl()     - convert character to printable form
  17.  
  18.   X/Open Description:
  19.        The unctrl routine expands the character c into a character
  20.        string which is a printable representation of the character.
  21.  
  22.        Control characters are displayed in the ^X notation.  Printing
  23.        characters are displayed normally.
  24.  
  25.   PDCurses Description:
  26.        The conversion from a control character to a two-character
  27.        sequence is done by the unctrl() function. In the BSD version
  28.        of curses it is done by a macro, which uses a publicly
  29.        available translation table. Some ill-behaved application
  30.        programs use the table directly, and since it does not exist
  31.        in this curses version such application will link with an
  32.        error message complainting about undefined symbols.
  33.  
  34.   X/Open Return Value:
  35.        The unctrl() function returns OK on success and ERR on error.
  36.  
  37.   X/Open Errors:
  38.        No errors are defined for this function.
  39.  
  40.   Portability:
  41.        PDCurses        char* unctrl( chtype c );
  42.        X/Open Dec '88  char* unctrl( chtype c );
  43.        BSD Curses      char* unctrl( chtype c );
  44.        SYS V Curses    char* unctrl( chtype c );
  45.  
  46. **man-end**********************************************************************/
  47.  
  48. char*  unctrl(chtype c)
  49. {
  50.        chtype  ic = c;
  51.  
  52.        ic &= A_CHARTEXT;
  53.        if (ic >= 0x20 && ic != 0x7f)           /* normal characters */
  54.        {
  55.                strbuf[0] = (char) ic;
  56.                strbuf[1] = '\0';
  57.                return( strbuf );
  58.        }
  59.        strbuf[0] = '^';        /* '^' prefix */
  60.        if (c == 0x7f)
  61.        {
  62.                /*
  63.                 * 0x7f == DEL
  64.                 */
  65.                strbuf[1] = '?';
  66.        }
  67.        else
  68.        {
  69.                /*
  70.                 * other control
  71.                 */
  72.                strbuf[1] = (char)(ic + '@');
  73.        }
  74.        return( strbuf );
  75. }
  76.